﻿@model ZDSoft.UPMS.Model.BusinessPart.Organization
@{
    Layout = null;
    IList<ZDSoft.UPMS.Model.SystemPart.User> teachers = TempData["teachers"] as IList<ZDSoft.UPMS.Model.SystemPart.User>;
}
<!DOCTYPE html>
<html>
<head>
    <title>Edit</title>
    <script src='@Url.Content("../../Scripts/jquery-1.5.1.min.js")' type="text/javascript"></script>
    <script src='@Url.Content("../../Scripts/formValidator-4.0.1.min.js")' type="text/javascript"></script>
    <script src='@Url.Content("../../Scripts/formValidatorRegex.js")' type="text/javascript"></script>
    <script src='@Url.Content("../../Scripts/auto/jquery.ajaxQueue.js")' type="text/javascript"></script>
    <script src='@Url.Content("../../Scripts/auto/jquery.autocomplete.js")' type="text/javascript"></script>
    <script src='@Url.Content("../../Scripts/auto/jquery.bgiframe.min.js")' type="text/javascript"></script>
    <script src='@Url.Content("../../Scripts/auto/thickbox-compressed.js")' type="text/javascript"></script>
    <link href='@Url.Content("../../Scripts/auto/main.css")' rel="stylesheet" type="text/css" />
    <link href='@Url.Content("../../Scripts/auto/thickbox.css")'  rel="stylesheet" type="text/css" />
    <link href='@Url.Content("../../Scripts/auto/jquery.autocomplete.css")'rel="stylesheet" type="text/css"/>
    <link href='@Url.Content("../../Scripts/PageCreater/Css/All.css")' rel="stylesheet" type="text/css" />
    <script language="javascript" type="text/javascript">
        var retVal = false;
        var i = 0;
        function SubmitPage() {
            $("#OrganlizationId").val($("#ResearcnName0").val());
            AddNodetest();

        }
        function editNodetest() {
            if ($("#Name").val() == "") {
                alert("不能为空哦！亲");
            }
            else {
                var re = new RegExp("[^%&',;=?$\x22]+");

                if (!re.test($("#Name").val())) {
                    alert("不能乱输入哦，亲！");
                }
                else {
                    var item = $(":input:checked");
                    var len = item.length;
                    if (len > 0) {
                        $("#exams").val("true");
                    }
                    else {

                        $("#exams").val("false");
                    }
                    var ispass = $("#exams").val();
                    var ID = $("#PerId").val();
                    var text = $("#Name").val();
                    $.post("/Organization/Updates", { ID: ID, Name: text, IsActive: ispass }, function () {
                        alert("提交成功！");

                    });
                    window.parent.editNode(text);
                }
            }
        }
        function AddNodetest() {
            var pid;
            var name;
            if ($("#ResearcnName0").val() == "") {
                alert("不能为空哦！亲");
            }
            else {
                var re = new RegExp("[^%&',;=?$\x22]+");

                if (!re.test($("#ResearcnName0").val())) {
                    alert("不能乱输入哦，亲！");
                }
                else {
                    var text = $("#ResearcnName0").val();
                    $.ajax({
                        type: "Post",
                        url: "/Organization/Update",
                        data: { OrganlizationId: $("#OrganlizationId").val(), Id: $("#id").val() },
                        success: function () {
                            $.post("/Organization/Text", function (data) { name = data });
                        }
                    });
                    alert("更新成功");
                    window.parent.AddNode(name);

                }
            }

        }
        function Show() {
            $("#Add").show();
        }
        function Hide() {
            $("#Add").hide();
        }
        $(document).ready(function () {
            $("#Add").hide();
        });

        function Shows() {
            $("#Principal").show();
        }
        function Hides() {
            $("#Principal").hide();
        }
        $(document).ready(function () {
            $("#Principal").hide();

        });
        var a;
        $(document).ready(function () {
            var a = $("#PersId").val();
            if (a == 'True') {
                $("#r_female").attr({ checked: "checked" });

            }
        })
        function SaveTeachers() {
            var selectedUsers = "";
            $("input:radio[checked='true']").each(function (i) {
                var id = $(this).attr("id");
                id = id.replace("chk_", "");
                selectedUsers = selectedUsers + "," + id;
            });
            $("#SelectedRoleByID").val(selectedUsers);
            var ID = $("#PerId").val();
            var select = $("#SelectedRoleByID").val();
            if (select == "") {
                alert("不能没有负责人哦！！");
            }
            else {
                $.post("/Organization/principals", { SelectedTeacherName: select, id: ID }, function () {
                    alert("提交成功！");

                });
            }

        }
    </script>
    <style type="text/css">
        #course
        {
            color: Blue;
        }
        #Name
        {
            width: 100px;
            border: 1px solid skyblue;
        }
    </style>
</head>
<body>
    <form id="form" method="post">
    <a href="#" onclick="Show()" style="color: Blue;">添加机构</a>
    @if (Model.SubOrganization != null)
    {
        @Html.ActionLink("配置课程", "ConfigurationOrgainazation", new { id = Model.ID }, new { @id = "course" })
    }
    <a href="#" onclick="Shows()" style="color: Blue;">负责人</a>
    <fieldset>
        机构名称:&nbsp;&nbsp;<input value="@TempData["Orname"]"  id="Name"  style="width: 120px; border: 1px solid skyblue;"/>
        <p>
            可&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 用: &nbsp;<input type="checkbox" id="r_female" /></p>
        <p>
            <input type="button" value="修改" onclick="editNodetest()" class="btn3" />
        </p>
    </fieldset>
    <fieldset id="Add" style="display: none;">
        <legend>下级机构</legend>机构名称：
        <input id="ResearcnName0" name="ResearcnName0" type="text" style="width: 120px; border: 1px solid skyblue;" />
        <p>
            <button type="button" onclick="SubmitPage()" class="btn3">
                保存</button>
            <button type="button" class="btn3" onclick="Hide()">
                关闭</button>
        </p>
        <input id="OrganlizationId" name="OrganlizationId" style="visibility: hidden" />
    </fieldset>
    <div id="Principal" style="display: none; width: 500px;">
        <fieldset style="width: 70%;">
            <legend>负责人名称</legend>
            <table style="width: 70%; font-size: 14px; border: 1px solid #007ea2; text-align: center;"
                id="teacherss">
                @if (teachers != null && teachers.Count != 0)
                { <tr class="blueTableTitle">
                    <td>
                        选择
                    </td>
                    <td>
                        负责人
                    </td>
                </tr>
                    foreach (var item in teachers)
                    {
                        var hasRole = false;
                        if (Model.ChargeMan != null)
                        {
                            if (item.ID == Model.ChargeMan.ID)
                            {
                                hasRole = true;
                            }
                        }
                    <tr>
                        <td>
                            @if (hasRole)
                            {
                                <input  name="teacherss" id="chk_ @item.ID" checked="checked" type="radio" />
                            }
                            else
                            {
                                <input   name="teacherss" id="chk_ @item.ID" type="radio" />
                            }
                        </td>
                        <td>
                            @item.Name
                        </td>
                    </tr>
                    }
                    <br />
                }
                else
                {
                    <tr>
                        <td>
                            当前机构下没有可用的教师
                        </td>
                    </tr>
                 
                }
            </table>
        </fieldset>
        <input type="hidden" name="id" id="id" value="@Model.ID" />
        <input type="hidden" name="org" id="org" value="@Model" />
        <input type="hidden" value="" id="exams" />
        <input type="button" onclick="SaveTeachers()" class="btn3" value="保存" />
        <input type="hidden" id="PerId" value="@TempData["id"]" />
        <input type="hidden" id="PersId" value="@TempData["Isactive"]" />
        <input id="SelectedRoleByID" name="SelectedRoleByID" type="hidden" />
        <input type="button" value="关闭" class="btn3" onclick="Hides()" />
    </div>
    </form>
</body>
</html>
